package com.study.algorithm.datastruct.graph;

import com.study.algorithm.datastruct.graph.model.Edge;
import com.study.algorithm.datastruct.graph.model.Graph;
import com.study.algorithm.datastruct.graph.model.Vertex;

import java.util.Collection;
import java.util.Set;

/**
 *  这里面的所有图类操作都是按照有向图来进行的（无向图请自行翻译)
 * 图的节点新增与移除操作，应该使用阻塞模型操作，
 * 原因：多线程操作同一个图的实例，非常危险
 * （所有的java对象应该都是一样的)
 */
public interface GraphBasicOperate {

    public <T extends Collection> boolean batchInsertVertex(Graph graph, T vertices);

    public <T extends Collection> boolean batchInsertEdge(Graph graph, T edges);

    public boolean containVertex(Graph graph, Vertex vertex);

    public Vertex containVertexAndReturnVertex(Graph graph, Vertex vertex);

    public void insertVertex(Graph graph, Vertex vertex);

    public boolean containEdge(Graph graph, Edge edge);

    public void insertOrUpdate(Graph graph, Edge edge);

    public boolean containNotUpdate(Graph graph, Edge edge);

    public boolean removeVertexAndEdge(Graph graph, Vertex vertex);

    public boolean removeEdge(Graph graph, Edge edge);

    public Set<Edge> queryEdgesContainVertex(Graph graph, Vertex vertex);

    public Edge getEdgeThroughStartAndEndVertex(Graph graph, Vertex startVertex, Vertex endVertex);

    public Set<Edge> queryEdgesUsingTheEndVertex(Graph graph, Vertex vertex);

    /**
     * 查找边集合（开始节点在startVertices集合中
     * 同时以endVertex节点结束）
     *
     * @param graph
     * @param startVertices 开始节点集合
     * @param startVertex
     * @return
     */
    public Set<Edge> queryEdgesUsingStartVertiesAndEndVetex(Graph graph, Set<Vertex> startVertices, Vertex startVertex);

    /**
     * 查找边集合（开始节点在startVertices集合中
     * 同时结束几点在endVertices集合中）
     *
     * @param graph
     * @param startVerties 开始顶点集合
     * @param endVerties   结束顶点集合
     * @return
     */
    public Set<Edge> queryEdgesUsingStartVertiesAndEndVerties(Graph graph, Set<Vertex> startVerties, Set<Vertex> endVerties);


    public Set<Edge> queryEdgesUsingTheStartVertex(Graph graph, Vertex vertex);

}
